

import java.util.ArrayList;
import java.net.URL;

public class EngineBase {
  /** Method to return the URLs from a query to this engine.
   * @param query The query to send to the engine.
   * @param numResults The maximum number of results to return.
   * @return A list of URLs relating to the query.
   */
  public ArrayList<String> doQuery(String query, int numResults){
    return null;
  }
  /** Return just the short host part of the url.
   *  Not abstract because it is static.
   * @param url The URL to strip.
   * @return The stripped URL as a string.
   */
  public static String URLStrip(String url) {
    String newURLStr = "";
    URL newURL = null;
    try {
      newURL = new URL(url);
    }
    catch(Exception e) {
      return url;
    }
    /* ABC and ABC are 2 different companies. */
    newURLStr = newURL.getHost().toLowerCase();
    if(newURLStr.endsWith("abc.net.au")) {
      return "abc-aus";
    }
    int index = newURLStr.indexOf(".") + 1;
    try {
      newURLStr = newURLStr.substring(index, newURLStr.indexOf(".", index));
    }
    catch(Exception e) {
      return newURL.getHost();
    }
    /* Known aliases. */
    if(newURLStr.equals("guardianfeeds") || newURLStr.equals("theguardian")) {
      return "guardian";
    }
    else if(newURLStr.equals("news")) {
      return "yahoo";
    }
    else if(newURLStr.equals("foxnews") || newURLStr.startsWith("myfox")) {
      return "fox";
    }
    else if(newURLStr.startsWith("sky")) {
      return "sky";
    }
    else if(newURLStr.startsWith("abc")) {
      return "abc";
    }
    return newURLStr;
  }
}
